package com.haojin.spring.config;

import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author .29.
 * @create 2023-03-02 9:33
 */
public class testBeanValidator {
    @Test
    public void testValidatorOne(){
        //获取context对象
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ValidationConfig.class);
        //校验器的实现类对象
        MyService1 myValidatorOne = context.getBean(MyService1.class);
        User user = new User();
        user.setAge(-1);
        boolean validator = myValidatorOne.validator(user);
        System.out.println(validator);
    }

    @Test
    public void testValidatorTwo(){
        //获取context对象
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(ValidationConfig.class);
        //校验器的实现类对象
        MyService2 myValidatorTwo = annotationConfigApplicationContext.getBean(MyService2.class);
        User user = new User();
        boolean validator = myValidatorTwo.validator2(user);
        System.out.println(validator);
    }
}
